home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3504 / 3504.xpi / components / zotero-service.js < prev   
Text File  |  2008-07-06  |  7KB  |  242 lines

  1. const ZOTERO_CONTRACTID = '@zotero.org/Zotero;1';
  2. const ZOTERO_CLASSNAME = 'Zotero';
  3. const ZOTERO_CID = Components.ID('{e4c61080-ec2d-11da-8ad9-0800200c9a66}');
  4. const ZOTERO_IID = Components.interfaces.chnmIZoteroService; //unused
  5.  
  6. const Cc = Components.classes;
  7. const Ci = Components.interfaces;
  8.  
  9. // Assign the global scope to a variable to passed via wrappedJSObject
  10. var ZoteroWrapped = this;
  11.  
  12.  
  13. /********************************************************************
  14. * Include the core objects to be stored within XPCOM
  15. *********************************************************************/
  16.  
  17. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  18.     .getService(Ci.mozIJSSubScriptLoader)
  19.     .loadSubScript("chrome://zotero/content/xpcom/zotero.js");
  20.  
  21. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  22.     .getService(Ci.mozIJSSubScriptLoader)
  23.     .loadSubScript("chrome://zotero/content/xpcom/db.js");
  24.  
  25. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  26.     .getService(Ci.mozIJSSubScriptLoader)
  27.     .loadSubScript("chrome://zotero/content/xpcom/schema.js");
  28.  
  29. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  30.     .getService(Ci.mozIJSSubScriptLoader)
  31.     .loadSubScript("chrome://zotero/content/xpcom/data_access.js");
  32.  
  33. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  34.     .getService(Ci.mozIJSSubScriptLoader)
  35.     .loadSubScript("chrome://zotero/content/xpcom/attachments.js");
  36.  
  37. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  38.     .getService(Ci.mozIJSSubScriptLoader)
  39.     .loadSubScript("chrome://zotero/content/xpcom/notifier.js");
  40.  
  41. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  42.     .getService(Ci.mozIJSSubScriptLoader)
  43.     .loadSubScript("chrome://zotero/content/xpcom/history.js");
  44.  
  45. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  46.     .getService(Ci.mozIJSSubScriptLoader)
  47.     .loadSubScript("chrome://zotero/content/xpcom/search.js");
  48.  
  49. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  50.     .getService(Ci.mozIJSSubScriptLoader)
  51.     .loadSubScript("chrome://zotero/content/xpcom/ingester.js");
  52.     
  53. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  54.     .getService(Ci.mozIJSSubScriptLoader)
  55.     .loadSubScript("chrome://zotero/content/xpcom/translate.js");
  56.     
  57. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  58.     .getService(Ci.mozIJSSubScriptLoader)
  59.     .loadSubScript("chrome://zotero/content/xpcom/cite.js");
  60.     
  61. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  62.     .getService(Ci.mozIJSSubScriptLoader)
  63.     .loadSubScript("chrome://zotero/content/xpcom/cite_compat.js");
  64.     
  65. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  66.     .getService(Ci.mozIJSSubScriptLoader)
  67.     .loadSubScript("chrome://zotero/content/xpcom/quickCopy.js");
  68.  
  69. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  70.     .getService(Ci.mozIJSSubScriptLoader)
  71.     .loadSubScript("chrome://zotero/content/xpcom/report.js");
  72.  
  73. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  74.     .getService(Ci.mozIJSSubScriptLoader)
  75.     .loadSubScript("chrome://zotero/content/xpcom/timeline.js");
  76.     
  77. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  78.     .getService(Ci.mozIJSSubScriptLoader)
  79.     .loadSubScript("chrome://zotero/content/xpcom/utilities.js");
  80.  
  81. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  82.     .getService(Ci.mozIJSSubScriptLoader)
  83.     .loadSubScript("chrome://zotero/content/xpcom/integration.js");
  84.  
  85. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  86.     .getService(Ci.mozIJSSubScriptLoader)
  87.     .loadSubScript("chrome://zotero/content/xpcom/file.js");
  88.  
  89. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  90.     .getService(Ci.mozIJSSubScriptLoader)
  91.     .loadSubScript("chrome://zotero/content/xpcom/fulltext.js");
  92.  
  93. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  94.     .getService(Ci.mozIJSSubScriptLoader)
  95.     .loadSubScript("chrome://zotero/content/xpcom/mime.js");
  96.  
  97. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  98.     .getService(Ci.mozIJSSubScriptLoader)
  99.     .loadSubScript("chrome://zotero/content/xpcom/itemTreeView.js");
  100.  
  101. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  102.     .getService(Ci.mozIJSSubScriptLoader)
  103.     .loadSubScript("chrome://zotero/content/xpcom/collectionTreeView.js");
  104.  
  105. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  106.     .getService(Ci.mozIJSSubScriptLoader)
  107.     .loadSubScript("chrome://zotero/content/xpcom/progressWindow.js");
  108.  
  109. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  110.     .getService(Ci.mozIJSSubScriptLoader)
  111.     .loadSubScript("chrome://zotero/content/xpcom/annotate.js");
  112.  
  113. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  114.     .getService(Ci.mozIJSSubScriptLoader)
  115.     .loadSubScript("chrome://global/content/nsTransferable.js");
  116.  
  117. Cc["@mozilla.org/moz/jssubscript-loader;1"]
  118.     .getService(Ci.mozIJSSubScriptLoader)
  119.     .loadSubScript("chrome://global/content/nsDragAndDrop.js");
  120.  
  121. /********************************************************************/
  122.  
  123.  
  124. // Initialize the Zotero service
  125. //
  126. // This runs when ZoteroService is first requested.
  127. // Calls to other XPCOM components must be in here rather than in top-level
  128. // code, as other components may not have yet been initialized.
  129. function setupService(){
  130.     try {
  131.         Zotero.init();
  132.     }
  133.     catch (e) {
  134.         var msg = typeof e == 'string' ? e : e.name;
  135.         dump(e + "\n\n");
  136.         Components.utils.reportError(e);
  137.         throw (e);
  138.     }
  139. }
  140.  
  141. function ZoteroService(){
  142.     this.wrappedJSObject = ZoteroWrapped.Zotero;
  143.     setupService();
  144. }
  145.  
  146.  
  147. /**
  148. * Convenience method to replicate window.alert()
  149. **/
  150. function alert(msg){
  151.     Cc["@mozilla.org/embedcomp/prompt-service;1"]
  152.         .getService(Ci.nsIPromptService)
  153.         .alert(null, "", msg);
  154. }
  155.  
  156. /**
  157. * Convenience method to replicate window.confirm()
  158. **/
  159. function confirm(msg){
  160.     return Cc["@mozilla.org/embedcomp/prompt-service;1"]
  161.         .getService(Ci.nsIPromptService)
  162.         .confirm(null, "", msg);
  163. }
  164.  
  165.  
  166. /**
  167. * Convenience method to replicate window.setTimeout()
  168. **/
  169. function setTimeout(func, ms){
  170.     var timer = Components.classes["@mozilla.org/timer;1"].
  171.         createInstance(Components.interfaces.nsITimer);
  172.     // {} implements nsITimerCallback
  173.     timer.initWithCallback({notify:func}, ms,
  174.         Components.interfaces.nsITimer.TYPE_ONE_SHOT);
  175. }
  176.  
  177.  
  178. //
  179. // XPCOM goop
  180. //
  181. ZoteroService.prototype = {
  182.     QueryInterface: function(iid){
  183.         if (!iid.equals(Components.interfaces.nsISupports) &&
  184.             !iid.equals(ZOTERO_IID)){ // interface unused
  185.             throw Components.results.NS_ERROR_NO_INTERFACE;
  186.         }
  187.         return this;
  188.     }
  189. };
  190.  
  191.  
  192. var ZoteroFactory = {
  193.     createInstance: function(outer, iid){
  194.         if (outer != null){
  195.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  196.         }
  197.         return new ZoteroService().QueryInterface(iid);
  198.     }
  199. };
  200.  
  201.  
  202. var ZoteroModule = {
  203.     _firstTime: true,
  204.     
  205.     registerSelf: function(compMgr, fileSpec, location, type){
  206.         if (!this._firstTime){
  207.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  208.         }
  209.         this._firstTime = false;
  210.         
  211.         compMgr =
  212.             compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  213.         
  214.         compMgr.registerFactoryLocation(ZOTERO_CID,
  215.                                         ZOTERO_CLASSNAME,
  216.                                         ZOTERO_CONTRACTID,
  217.                                         fileSpec,
  218.                                         location,
  219.                                         type);
  220.     },
  221.     
  222.     unregisterSelf: function(compMgr, location, type){
  223.         compMgr =
  224.             compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  225.         compMgr.unregisterFactoryLocation(ZOTERO_CID, location);
  226.     },
  227.     
  228.     getClassObject: function(compMgr, cid, iid){
  229.         if (!cid.equals(ZOTERO_CID)){
  230.             throw Components.results.NS_ERROR_NO_INTERFACE;
  231.         }
  232.         if (!iid.equals(Components.interfaces.nsIFactory)){
  233.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  234.         }
  235.         return ZoteroFactory;
  236.     },
  237.     
  238.     canUnload: function(compMgr){ return true; }
  239. };
  240.  
  241. function NSGetModule(comMgr, fileSpec){ return ZoteroModule; }
  242.